var __FUSION_CHARTS_PATH = __CONTEXT_PATH+"/fusioncharts/charts/";
function Chart(id, viewmodel) {
	this.viewmodel=viewmodel;
	this.width=500;
	this.height=300;
	this.dataset=null;
	this.chartDiv = null;
	this.chartType = null;
	this.swfFile = null;
	this.labelField = null;
	this.valueFields = null;
	this.valueDropDown = null;
	this.valueFieldAsCategory=false;
	this.needConvertData = false;
	this._divId = null;
	this._id = id;
	this._attr_list={};
	this._fusion_charts = null;
	this._isRenderer = false;
	this._buildDocumentRoot = __FusionCharts_buildDocumentRoot;
	this._setChartType=__FusionCharts_setChartType;
};

Chart.prototype = new DoradoComponent();
// 设置自定义组件默认Doraodo JS 事件
Chart.prototype.getId=__DoradoComponent_getId;
Chart.prototype.getViewModel=__DoradoComponent_getViewModel;
Chart.prototype.getTag=__DoradoElement_getTag;
Chart.prototype.setTag=__DoradoElement_setTag;
Chart.prototype.isActive=__DoradoComponent_isActive;
Chart.prototype.activate=__DataControl_activate;

Chart.prototype.getDataset=__DataControl_getDataset;
Chart.prototype.setDataset=__DataControl_setDataset;

Chart.prototype.establishBinding=__DataControl_establishBinding;
Chart.prototype.$7c=__DataControl_disposeBinding;
Chart.prototype.disableBinding=__DataControl_disableBinding;
Chart.prototype.enableBinding=__DataControl_enableBinding;

// 初始化自定义组件执行
Chart.prototype.processDatasetMessage=function(message,dataset,args){
	switch(message){
		case __Dataset_MSG_REFRESH:{
			// alert("__Dataset_MSG_REFRESH");
			this.renderer();
		}
		/*
		 * case __Dataset_MSG_DATA_CHANGED:{
		 * alert("__Dataset_MSG_DATA_CHANGED"); this.renderer(); break; }
		 */
	}
};
function __FusionCharts_buildDocumentRoot(xmlDoc) {
	var chart = xmlDoc.createElement("chart");
	for ( var attr in this._attr_list) {
		chart.setAttribute(attr,this._attr_list[attr]);
	}
	return chart;
};
function __FusionCharts_setChartType(chartType) {
	var chartSwf = {
			"Column2D" : "Column2D.swf",
			"Column3D" : "Column3D.swf",
			"MSColumn2D" : "MSColumn2D.swf",
			"MSColumn3D" : "MSColumn3D.swf",
			"Pie2D" : "Pie2D.swf",
			"Pie3D" : "Pie3D.swf",
			"Doughnut2D" : "Doughnut2D.swf",
			"Doughnut3D" : "Doughnut3D.swf",
			"Line" : "Line.swf",
			"MSLine" : "MSLine.swf",
			"Area" : "Area2D.swf",
			"MSArea" : "MSArea.swf",
			"Bar2D" : "Bar2D.swf",
			"MSBar2D" : "MSBar2D.swf",
			"MSBar3D" : "MSBar3D.swf",
			"ScrollLine2D" : "ScrollLine2D.swf",
			"ScrollColumn2D" : "ScrollColumn2D.swf",
			"ScrollArea2D" : "ScrollArea2D.swf",
			"ScrollStackedColumn2D" : "ScrollStackedColumn2D.swf"
		};
	if (typeof (chartSwf[chartType]) == "undefined") {
		alert("图表类型\"" + chartType + "\"未实现.");
		return false;
	}
	this.chartType = chartType;
	this.swfFile = chartSwf[chartType];
};
Chart.prototype.beforeRenderer = function(){
	var isContinue = fireDoradoEvent(this, "beforeRenderer", [this]);
	if(!isContinue && typeof(isContinue) != "undefined"){
		return false;
	}
	return true;
}
//创建xml时的一些事件支持
Chart.prototype.onBuildCategories=function(categories,xmlDoc){
	fireDoradoEvent(this, "onBuildCategories", [this,categories,xmlDoc]);
}
Chart.prototype.onBuildCategory=function(category,categoryValue,xmlDoc){
	fireDoradoEvent(this, "onBuildCategory", [this,category,categoryValue,xmlDoc]);
}
Chart.prototype.onBuildCateSet=function(cateSet,cateSetKey,xmlDoc){
	fireDoradoEvent(this, "onBuildCateSet", [this,cateSet,cateSetKey,xmlDoc]);
}
Chart.prototype.onBuildSet=function(set,record,categoryValue,seriesValue,xmlDoc){
	fireDoradoEvent(this, "onBuildSet", [this,set,record,categoryValue,seriesValue,xmlDoc]);
}
// XML收集完成之后的操作
Chart.prototype.afterBuildXML = function(fusionCharts,root,xmlDoc){
	fireDoradoEvent(this, "afterBuildXML", [this,fusionCharts,root,xmlDoc]);
}
Chart.prototype._getFusionCharts=function(swfFilePath){
	if(this._fusion_charts){
		return this._fusion_charts;
	}
	var chart = new FusionCharts(swfFilePath, this._id, this
			.getWidth(), this.getHeight(),0,1);
	 // 设置Flash文件为透明
	chart.addParam("wmode","Opaque");
	chart.addParam("wmode","transparent");
	this._fusion_charts = chart;
	return this._fusion_charts;
}
// 进行图表的页面渲染
Chart.prototype.renderer = function(){
	this.dataset = this.getDataset();
	if (!this.dataset) {
		alert('属性"dataset"未设置.');
		return false;
	}
	if (!this.swfFile) {
		alert('图表类型未设置.');
		return false;
	}
	if(!this.beforeRenderer()){
		return false;
	}
	var xmlDoc = ChartUtil.getXmlDoc();
	var root = this._buildDocumentRoot(xmlDoc);
	this.buildChartXML(root,xmlDoc);
	// TODO add other futher
	var chart = this._getFusionCharts(__FUSION_CHARTS_PATH + this.swfFile);
	this.afterBuildXML(chart,root,xmlDoc);
	chart.setDataXML(ChartUtil.toXML(root));
	if(!this._isRenderer){
		chart.render(this._divId);
		this._isRenderer = true;
	}
}
// 具体生成chart xml内容的函数由子类来决定,默认采用多序列的方式生成数据
Chart.prototype.buildChartXML = function(root,xmlDoc) {
	ChartUtil.buildMultiSet(this,this.getDataset(), this.labelField, this.valueFields.split(","),this.valueDropDown, root, xmlDoc);
};
Chart.prototype.setNeedConvertData=function(needConvertData){
	this.needConvertData = needConvertData;
}
Chart.prototype.getNeedConvertData = function(){
	return this.needConvertData;
}
// 将valueField做为category;
Chart.prototype.setValueFieldAsCategory = function(valueFieldAsCategory){
	this.valueFieldAsCategory = valueFieldAsCategory;
}
Chart.prototype.getValueFieldAsCategory = function(){
	return this.valueFieldAsCategory;
}
// x轴所在的field
Chart.prototype.setLabelField = function(labelField) {
	this.labelField = labelField;
};
Chart.prototype.getLabelField = function() {
	return this.labelField;
};
// y轴显示值所在的位置
Chart.prototype.setValueFields = function(valueFields) {
	this.valueFields = valueFields;
};
Chart.prototype.getValueFields = function() {
	return this.valueFields;
};
Chart.prototype.setValueDropDown=function(valueDropDown){
	this.valueDropDown = valueDropDown;
}
Chart.prototype.getValueDropDown = function() {
	return this.valueDropDown;
};

// 宽高设置
Chart.prototype.setWidth = function(width) {
	this.width = width;
};
Chart.prototype.getWidth = function() {
	return this.width;
};
Chart.prototype.setHeight = function(height) {
	this.height = height;
};
Chart.prototype.getHeight = function() {
	return this.height;
};
// 图表的一些基本属性设置
// caption
Chart.prototype.setCaption = function(caption) {
	this.setAttr("caption", caption);
};
Chart.prototype.getCaption = function() {
	return this.getAttr("caption");
};
// subCaption
Chart.prototype.setSubCaption = function(subCaption) {
	this.setAttr("subCaption", subCaption);
};
Chart.prototype.getSubCaption = function() {
	return this.getAttr("subCaption");
};
// xAxisName
Chart.prototype.setXAxisName = function(xAxisName) {
	this.setAttr("xAxisName", xAxisName);
};
Chart.prototype.getXAxisName = function() {
	return this.getAttr("xAxisName");
};
// yAxisName
Chart.prototype.setYAxisName = function(yAxisName) {
	this.setAttr("yAxisName", yAxisName);
};
Chart.prototype.getYAxisName = function() {
	return this.getAttr("yAxisName");
};
// bgColor
Chart.prototype.setBgColor = function(bgColor) {
	this.setAttr("bgColor", bgColor);
};
Chart.prototype.getBgColor = function() {
	return this.getAttr("bgColor");
};
// bgAlpha
Chart.prototype.setBgAlpha = function(bgAlpha) {
	this.setAttr("bgAlpha", bgAlpha);
};
Chart.prototype.getBgAlpha = function() {
	return this.getAttr("bgAlpha");
};
// labelStep
Chart.prototype.setLabelStep = function(labelStep) {
	this.setAttr("labelStep", labelStep);
};
Chart.prototype.getLabelStep = function() {
	return this.getAttr("labelStep");
};
// showLabels
Chart.prototype.setShowLabels = function(showLabels) {
	this.setAttr("showLabels", ChartUtil.parseBoolean(showLabels));
};
Chart.prototype.getShowLabels = function() {
	return this.getAttr("showLabels");
};

// showValues
Chart.prototype.setShowValues = function(showValues) {
	this.setAttr("showValues", ChartUtil.parseBoolean(showValues));
};
Chart.prototype.getShowValues = function() {
	return this.getAttr("showValues");
};
// baseFont
Chart.prototype.setBaseFont = function(baseFont) {
	this.setAttr("baseFont", baseFont);
};
Chart.prototype.getBaseFont = function() {
	return this.getAttr("baseFont");
};
// baseFontSize
Chart.prototype.setBaseFontSize = function(baseFontSize) {
	this.setAttr("baseFontSize", baseFontSize);
};
Chart.prototype.getBaseFontSize = function() {
	return this.getAttr("baseFontSize");
}
// baseFontColor
Chart.prototype.setBaseFontSize = function(baseFontColor) {
	this.setAttr("baseFontColor", baseFontColor);
};
Chart.prototype.getBaseFontColor = function() {
	return this.getAttr("baseFontColor");
}
// palette
Chart.prototype.setPalette = function(palette) {
	this.setAttr("palette", palette);
};
Chart.prototype.getPalette = function() {
	return this.getAttr("palette");
}
// paletteColors
Chart.prototype.setPaletteColors = function(paletteColors) {
	this.setAttr("paletteColors", paletteColors);
};
Chart.prototype.getPaletteColors = function() {
	return this.getAttr("paletteColors");
}
// yAxisMinValue
Chart.prototype.setYAxisMinValue = function(yAxisMinValue) {
	this.setAttr("yAxisMinValue", yAxisMinValue);
};
Chart.prototype.getYAxisMinValue = function() {
	return this.getAttr("yAxisMinValue");
}
// yAxisMaxValue
Chart.prototype.setYAxisMaxValue = function(yAxisMaxValue) {
	this.setAttr("yAxisMaxValue", yAxisMaxValue);
};
Chart.prototype.getYAxisMaxValue = function() {
	return this.getAttr("yAxisMaxValue");
}
// setAdaptiveYMin
Chart.prototype.setSetAdaptiveYMin = function(setAdaptiveYMin) {
	this.setAttr("setAdaptiveYMin", ChartUtil.parseBoolean(setAdaptiveYMin));
};
Chart.prototype.getSetAdaptiveYMin = function() {
	return this.getAttr("setAdaptiveYMin");
}
// showToolTip
Chart.prototype.setShowToolTip = function(showToolTip) {
	this.setAttr("showToolTip", ChartUtil.parseBoolean(showToolTip));
};
Chart.prototype.getShowToolTip = function() {
	return this.getAttr("showToolTip");
}
// chartLeftMargin
Chart.prototype.setChartLeftMargin = function(chartLeftMargin) {
	this.setAttr("chartLeftMargin", chartLeftMargin);
};
Chart.prototype.getChartLeftMargin = function() {
	return this.getAttr("chartLeftMargin");
}
// chartRightMargin
Chart.prototype.setChartRightMargin = function(chartRightMargin) {
	this.setAttr("chartRightMargin", chartRightMargin);
};
Chart.prototype.getChartRightMargin = function() {
	return this.getAttr("chartRightMargin");
}
// chartTopMargin
Chart.prototype.setChartTopMargin = function(chartTopMargin) {
	this.setAttr("chartTopMargin", chartTopMargin);
};
Chart.prototype.getChartTopMargin = function() {
	return this.getAttr("chartTopMargin");
}
// chartBottomMargin
Chart.prototype.setChartBottomMargin = function(chartBottomMargin) {
	this.setAttr("chartBottomMargin", chartBottomMargin);
};
Chart.prototype.getChartBottomMargin = function() {
	return this.getAttr("chartBottomMargin");
}
// decimals
Chart.prototype.setDecimals = function(decimals) {
	this.setAttr("decimals", decimals);
};
Chart.prototype.getDecimals = function() {
	return this.getAttr("decimals");
}
// forceDecimals
Chart.prototype.setForceDecimals = function(forceDecimals) {
	this.setAttr("forceDecimals", ChartUtil.parseBoolean(forceDecimals));
};
Chart.prototype.getForceDecimals = function() {
	return this.getAttr("forceDecimals");
}
// formatNumberScale
Chart.prototype.setForamtNumberScale = function(formatNumberScale) {
	this.setAttr("formatNumberScale", ChartUtil.parseBoolean(formatNumberScale));
};
Chart.prototype.getFormatNumberScale = function() {
	return this.getAttr("formatNumberScale");
}
// formatNumber
Chart.prototype.setFormatNumber = function(formatNumber) {
	this.setAttr("formatNumber", ChartUtil.parseBoolean(formatNumber));
};
Chart.prototype.getFormatNumber = function() {
	return this.getAttr("formatNumber");
}
// numberPrefix
Chart.prototype.setNumberPrefix = function(numberPrefix) {
	this.setAttr("numberPrefix", numberPrefix);
};
Chart.prototype.getNumberPrefix = function() {
	return this.getAttr("numberPrefix");
}
// numberSuffix
Chart.prototype.setNumberSuffix = function(numberSuffix) {
	this.setAttr("numberSuffix", numberSuffix);
};
Chart.prototype.getNumberSuffix = function() {
	return this.getAttr("numberSuffix");
}
// numberScaleValue
Chart.prototype.setNumberScaleValue = function(numberScaleValue) {
	this.setAttr("numberScaleValue", numberScaleValue);
};
Chart.prototype.getNumberScaleValue = function() {
	return this.getAttr("numberScaleValue");
}
// numberScaleUnit
Chart.prototype.setNumberScaleUnit = function(numberScaleUnit) {
	this.setAttr("numberScaleUnit", numberScaleUnit);
};
Chart.prototype.getNumberScaleUnit = function() {
	return this.getAttr("numberScaleUnit");
}
// clickURL
Chart.prototype.setClickURL = function(clickURL) {
	this.setAttr("clickURL", clickURL);
};
Chart.prototype.getClickURL = function() {
	return this.getAttr("clickURL");
}
//数据导出的支持
//exportEnabled
Chart.prototype.setExportEnabled = function(exportEnabled) {
	this.setAttr("exportEnabled", ChartUtil.parseBoolean(exportEnabled));
	this.setAttr("exportAtClient", "1");//只支持客户端的导出
};
Chart.prototype.getExportEnabled = function() {
	return this.getAttr("exportEnabled");
}
//exportHandler
Chart.prototype.setExportHandler = function(exportHandler) {
	this.setAttr("exportHandler", exportHandler);
};
Chart.prototype.getExportHandler = function() {
	return this.getAttr("exportHandler");
}

// 更为通用的设置属性方式
Chart.prototype.setAttr = function(attr, value) {
	this._attr_list[attr] = value;
};
Chart.prototype.getAttr = function(attr) {
	return typeof (this._attr_list[attr]) == "undefined" ? null
			: this._attr_list[attr];
};
// 工具类
var ChartUtil = {
	$getControl:function(control){
		if(control && typeof(control)=="string"){
			control = getControl(control);
		}
		return control;
	},
	$getDropDown:function(dataset,field){
		var dropdown = dataset.getField(field).getDropDown();
		return this.$getControl(dropdown);
	},
	parseBoolean:function(value){
		return !value || value =="false" || value == "" || value==false ? 0 : 1;
	},
	buildSingleSet:function(chart,dataset,labelField,valueField,root,xmlDoc){
		var r = dataset.getFirstRecord();
		var labelDropDown = this.$getDropDown(dataset,labelField);
		var labelValue;
		var labelDisplay;
		var set;
		while(r){
			set = xmlDoc.createElement("set");
			labelValue = r.getValue(labelField);
			labelDisplay = labelDropDown ? labelDropDown.getLabel(labelValue) : null;
			set.setAttribute("label",labelDisplay ? labelDisplay : labelValue);
			set.setAttribute("value",r.getString(valueField));
			//创建set时的事件
			chart.onBuildSet(set,r,null,null,xmlDoc);
			root.appendChild(set);
			r = r.getNextRecord();
		}
	},
	buildMultiSet:function(chart,dataset,labelField,valueFields,valueDropDown,root,xmlDoc){
		
		var $$util ={
				xmlDoc:xmlDoc,
				/**
				 * 对于一个给定的值value，获取最终要显示的值;
				 * 该显示值可以通过dropdown.getLabel()得到，如果dropdown中无法获取到该显示值，将使用defaultDisplay作为显示值
				 */
				getDisplayValue : function(value,dropdown,defaultDisplay){
					defaultDisplay = defaultDisplay || value;
					var displayValue = dropdown ? dropdown.getLabel(value) : null;
					return displayValue ? displayValue : defaultDisplay;
				},
				createCategories:function(){
					return this.xmlDoc.createElement("categories");
				},
				createCategory : function(categoryName){
					var category = this.xmlDoc.createElement("category");
					category.setAttribute("label",categoryName);
					return category;
				},
				createCateSet : function(seriesName){
					var cataSet = this.xmlDoc.createElement("dataset");
					cataSet.setAttribute("seriesName",seriesName);
					return cataSet;
				},
				createSet : function(value){
					var set = this.xmlDoc.createElement("set");
					value && value!=null && value!="" && set.setAttribute("value",value);
					return set;
				}
		}
		
		
		var categories;
		var category;
		var categoryValue;
		var valueField;
		var cataSet;
		var set;
		var labelDropDown = ChartUtil.$getDropDown(dataset,labelField);
		var labelValue;
		/**
		 * 在valueFieldsAsCategory属性为false时，构造所需的XML格式
		 */
		var $buildXMLWhenValueFieldAsCategoryNo = function(chart,dataset,labelField,valueFields,valueDropDown,root,xmlDoc){
			
			valueDropDown = ChartUtil.$getControl(valueDropDown);
			categories = $$util.createCategories();
			//事件支持
			chart.onBuildCategories(categories,xmlDoc);
			root.appendChild(categories);
			
			var cataSetMap = {};
			for(var i = 0;i < valueFields.length;i++){
				valueField = dataset.getField(valueFields[i]);
				labelValue = valueField.getName();
				cataSet = $$util.createCateSet($$util.getDisplayValue(labelValue,valueDropDown,valueField.getLabel()));
				//事件支持
				chart.onBuildCateSet(cataSet,labelValue,xmlDoc);
				cataSetMap[valueFields[i]] = cataSet;
				root.appendChild(cataSet);
			}
			var r = dataset.getFirstRecord();
			while(r){
				categoryValue = r.getValue(labelField);
				category = $$util.createCategory($$util.getDisplayValue(categoryValue,labelDropDown));
				//事件支持
				chart.onBuildCategory(category,categoryValue,xmlDoc);
				categories.appendChild(category);
				for(var i = 0;i < valueFields.length;i++){
					set = $$util.createSet(r.getValue(valueFields[i]));
					//事件支持
					chart.onBuildSet(set,r,categoryValue,valueFields[i],xmlDoc);
					cataSetMap[valueFields[i]].appendChild(set);
				}
				r = r.getNextRecord();
			}
		};

		/**
		 * 在valueFieldsAsCategory属性为true时，构造所需的XML格式
		 */
		var $buildXMLWhenValueFieldAsCategory = function(chart,dataset,labelField,valueFields,valueDropDown,root,xmlDoc){
			valueDropDown = ChartUtil.$getControl(valueDropDown);
			categories = $$util.createCategories();
			//事件支持
			chart.onBuildCategories(categories,xmlDoc);
			for(var i = 0;i < valueFields.length;i++){
				valueField = dataset.getField(valueFields[i]);
				categoryValue = valueField.getName();
				category = $$util.createCategory($$util.getDisplayValue(categoryValue,valueDropDown,valueField.getLabel()));
				//事件支持
				chart.onBuildCategory(category,categoryValue,xmlDoc);
				categories.appendChild(category);
			}
			root.appendChild(categories);
			var r = dataset.getFirstRecord();
			while(r){
				labelValue = r.getValue(labelField);
				cataSet = $$util.createCateSet($$util.getDisplayValue(labelValue,labelDropDown));
				//事件支持
				chart.onBuildCateSet(cataSet,labelValue,xmlDoc);
				for(var i = 0;i < valueFields.length;i++){
					set = $$util.createSet(r.getValue(valueFields[i]));
					//事件支持
					chart.onBuildSet(set,r,valueFields[i],labelValue,xmlDoc);
					cataSet.appendChild(set);
				}
				root.appendChild(cataSet);
				r = r.getNextRecord();
			}
		}
		/**
		 * 
		 */
		var $buildXMLWhileNeedConvertData = function(chart,dataset,labelField,valueFields,valueDropDown,root,xmlDoc){
			// xml结构数据，xmlArr的key为category的value(即为valueLabelField的值),值为另一个object对象,该对象的key为labelField的value;
			var xmlArr = {};
			var categoryArr = {};
			
			var $findCateSet=function(seriesName){
				if(!(seriesName in xmlArr)){
					/*var cateSet = {};
					for(var category in categoryArr){
						cateSet[category]=null;
					}*/
					xmlArr[seriesName]={};
				}
				return xmlArr[seriesName];
			}
			
			var $addCategory=function(category){
				if(!(category in categoryArr)){
					/*for(var cateSet in xmlArr){
						cateSet[category]=null;
					}*/
					categoryArr[category]=category;
				}
			}
			var seriesField = valueFields[0];
			var valueField = valueFields[1];
			var seriesName;
			var categoryName;
			var cateSet;
			var r = dataset.getFirstRecord();
			while(r){
				categoryName = r.getValue(labelField);
				seriesName = r.getValue(seriesField);
				$addCategory(categoryName);
				cateSet = $findCateSet(seriesName);
				cateSet[categoryName]=r;
				r = r.getNextRecord();
			}
			categories = $$util.createCategories();
			//事件支持
			chart.onBuildCategories(categories,xmlDoc);
			valueDropDown = ChartUtil.$getControl(valueDropDown);
			//如果没有配置dropdown,可以使用该field中配置的dropdown来使用
			var cateSetDropDown = valueDropDown ? valueDropDown : ChartUtil.$getDropDown(dataset, seriesField);
			for(var _category in categoryArr){
				category = $$util.createCategory($$util.getDisplayValue(_category,labelDropDown));
				//事件支持
				chart.onBuildCategory(category,_category,xmlDoc);
				categories.appendChild(category);
			}
			root.appendChild(categories);
			for(var _cateSet in xmlArr){
				var _cateSetValue = xmlArr[_cateSet];
				cataSet = $$util.createCateSet($$util.getDisplayValue(_cateSet,cateSetDropDown));
				//事件支持
				chart.onBuildCateSet(cataSet,_cateSet,xmlDoc);
				for(var _category in categoryArr){
					var value = null;
					var r = null;
					if(typeof (_cateSetValue[_category])!="undefined"){
						//该系列的_category有值
						r = _cateSetValue[_category];
						value = r.getValue(valueField);
					}
					//事件支持
					chart.onBuildSet(cataSet,_cateSet,xmlDoc);
					set = $$util.createSet(value);
					//事件支持
					chart.onBuildSet(set,r,_category,_cateSet,xmlDoc);
					cataSet.appendChild(set);
				}
				root.appendChild(cataSet);
			}
		}
		if(chart.needConvertData){
			// 需要对dataset的数据进行转换,此时dataset中的数据不能直接被用来封装 fusioncharts XML
			$buildXMLWhileNeedConvertData(chart,dataset,labelField,valueFields,valueDropDown,root,xmlDoc);
		} else {
			if(chart.valueFieldAsCategory){
				$buildXMLWhenValueFieldAsCategory(chart,dataset,labelField,valueFields,valueDropDown,root,xmlDoc);
			} else {
				$buildXMLWhenValueFieldAsCategoryNo(chart,dataset,labelField,valueFields,valueDropDown,root,xmlDoc);
			}
		}
	},
	getXmlDoc:function(){
		var xmlDoc;
		if(window.ActiveXObject) {  
		xmlDoc = new ActiveXObject('Microsoft.XMLDOM');  
		} else  if (document.implementation&&document.implementation.createDocument){  
		xmlDoc = document.implementation.createDocument('', '', null);  
		}
		return xmlDoc;
	},
	toXML:function(element){
		if(window.ActiveXObject){
			return element.xml;
		}else{
			return (new XMLSerializer()).serializeToString(element)
		}
	}
};
// ColumnChart
function ColumnChart(id, viewmodel) {
	Chart.call(this, id, viewmodel);
	this.show3D = false;
	this._isMulti;
}
ColumnChart.prototype = new Chart();
ColumnChart.prototype.constructor = Chart;
DoradoFactory.registerComponentType("ColumnChart", function(id,viewmodel){return new ColumnChart(id,viewmodel);});
ColumnChart.prototype._superRenderer = Chart.prototype.renderer;
ColumnChart.prototype.renderer=function(){
	this._isMulti = this.valueFields.split(",").length>1;
	if(this.show3D){
		this._setChartType(this._isMulti ? "MSColumn3D" : "Column3D");
	} else {
		this._setChartType(this._isMulti ? "MSColumn2D" : "Column2D");
	}
	this._superRenderer();
};

ColumnChart.prototype.setShow3D=function(show3D){
	this.show3D = show3D;
};
ColumnChart.prototype.getShow3D=function(){
	return this.show3D;
};
ColumnChart.prototype._superBuildChartXML = Chart.prototype.buildChartXML;
ColumnChart.prototype.buildChartXML = function(root,xmlDoc) {
	// create categories
	if(!this._isMulti){
		ChartUtil.buildSingleSet(this,this.getDataset(), this.labelField, this.valueFields, root, xmlDoc);
	} else {
		this._superBuildChartXML(root,xmlDoc);
	}
};
// LineChart
function LineChart(id, viewmodel,$chartType,$msChartType) {
	Chart.call(this, id, viewmodel);
	this._isMulti;
	this._chartType = $chartType || "Line";
	this._msChartType = $msChartType || "MSLine";
}
LineChart.prototype = new Chart();
LineChart.prototype.constructor = Chart;
DoradoFactory.registerComponentType("LineChart", function(id,viewmodel){return new LineChart(id,viewmodel);});
LineChart.prototype._superRenderer = Chart.prototype.renderer;
LineChart.prototype.renderer=function(){
	this._isMulti = this.valueFields.split(",").length>1;
	this._setChartType(this._isMulti ? this._msChartType : this._chartType);
	this._superRenderer();
};

LineChart.prototype._superBuildChartXML = Chart.prototype.buildChartXML;
LineChart.prototype.buildChartXML = function(root,xmlDoc) {
	// create categories
	if(!this._isMulti){
		ChartUtil.buildSingleSet(this,this.getDataset(), this.labelField, this.valueFields, root, xmlDoc);
	} else {
		this._superBuildChartXML(root,xmlDoc);
	}
};

// AreaChart,其与LineChart的属性及数据形式一致，只是展现时所用的图表不同
function AreaChart(id, viewmodel) {
	LineChart.call(this, id, viewmodel,"Area","MSArea");
}
AreaChart.prototype = new LineChart();
AreaChart.prototype.constructor = LineChart;
DoradoFactory.registerComponentType("AreaChart", function(id,viewmodel){return new AreaChart(id,viewmodel);});
// PieChart
function PieChart(id, viewmodel,$chartType2D,$ChartType3D) {
	Chart.call(this, id, viewmodel);
	this.show3D = false;
	this._chartType2D = $chartType2D || "Pie2D";
	this._ChartType3D = $ChartType3D || "Pie3D";
}
PieChart.prototype = new Chart();
PieChart.prototype.constructor = Chart;
DoradoFactory.registerComponentType("PieChart", function(id,viewmodel){return new PieChart(id,viewmodel);});
PieChart.prototype._superRenderer = Chart.prototype.renderer;
PieChart.prototype.renderer=function(){
	this._setChartType(this.show3D ? this._ChartType3D : this._chartType2D);
	this._superRenderer();
};

PieChart.prototype.setShow3D=function(show3D){
	this.show3D = show3D;
};
PieChart.prototype.getShow3D=function(){
	return this.show3D;
};
PieChart.prototype.buildChartXML = function(root,xmlDoc) {
	// create categories
	ChartUtil.buildSingleSet(this,this.getDataset(), this.labelField, this.valueFields, root, xmlDoc);
};
// DoughnutChart 其与PieChart的属性及数据形式一样，只是展现形式不同，可以使用PieChart做为其父类
function DoughnutChart(id, viewmodel) {
	PieChart.call(this, id, viewmodel,"Doughnut2D","Doughnut3D");
}
DoughnutChart.prototype = new PieChart();
DoughnutChart.prototype.constructor = PieChart;
DoradoFactory.registerComponentType("DoughnutChart", function(id,viewmodel){return new DoughnutChart(id,viewmodel);});

// BarChart
function BarChart(id, viewmodel) {
	Chart.call(this, id, viewmodel);
	this.show3D = false;
	this._isMulti;
}
BarChart.prototype = new Chart();
BarChart.prototype.constructor = Chart;
DoradoFactory.registerComponentType("BarChart", function(id,viewmodel){return new BarChart(id,viewmodel);});
BarChart.prototype._superRenderer = Chart.prototype.renderer;
BarChart.prototype.renderer=function(){
	this._isMulti = this.valueFields.split(",").length>1;
	if(this._isMulti){
		this._setChartType(this.show3D ? "MSBar3D" : "MSBar2D");
	} else {
		this._setChartType("Bar2D");
	}
	this._superRenderer();
};

BarChart.prototype.setShow3D=function(show3D){
	this.show3D = show3D;
};
BarChart.prototype.getShow3D=function(){
	return this.show3D;
};
BarChart.prototype._superBuildChartXML = Chart.prototype.buildChartXML;
BarChart.prototype.buildChartXML = function(root,xmlDoc) {
	// create categories
	if(!this._isMulti){
		ChartUtil.buildSingleSet(this,this.getDataset(), this.labelField, this.valueFields, root, xmlDoc);
	} else {
		this._superBuildChartXML(root,xmlDoc);
	}
};

// ScrollSimpleChart,包括ScrollLine2D,ScrollColumn2D,ScrollArea2D,ScrollStackedColumn2D
function ScrollSimpleChart(id, viewmodel) {
	Chart.call(this, id, viewmodel);
}
ScrollSimpleChart.prototype = new Chart();
ScrollSimpleChart.prototype.constructor = Chart;
DoradoFactory.registerComponentType("ScrollSimpleChart", function(id,viewmodel){return new ScrollSimpleChart(id,viewmodel);});
ScrollSimpleChart.prototype.setChartType=function(chartType){
	if(chartType=="line"){
		this._setChartType("ScrollLine2D");
	} else if(chartType=="column"){
		this._setChartType("ScrollColumn2D");
	} else if(chartType=="area"){
		this._setChartType("ScrollArea2D");
	} else if(chartType=="stackedColumn"){
		this._setChartType("ScrollStackedColumn2D");
	}
};

ScrollSimpleChart.prototype.setNumVisiblePlot=function(numVisiblePlot){
	this.setAttr("numVisiblePlot", numVisiblePlot);
};
ScrollSimpleChart.prototype.getNumVisiblePlot=function(){
	return this.getAttr("numVisiblePlot");
};

ScrollSimpleChart.prototype.setScrollToEnd=function(scrollToEnd){
	this.setAttr("scrollToEnd", ChartUtil.parseBoolean(scrollToEnd));
};
ScrollSimpleChart.prototype.getScrollToEnd=function(){
	return this.getAttr("scrollToEnd");
};
/**
 * 数据导出组件
 * @param id
 * @param viewmodel
 * @returns {___handler0}
 */
function ExportHandler(id,viewmodel){
	var divId="div_"+id;
	var handler = document.getElementById(divId);
	//设置自定义组件默认Doraodo JS 事件
	handler.getId = __DoradoComponent_getId;
	handler.getViewModel=__DoradoComponent_getViewModel;
	handler.isActive=__DoradoComponent_isActive;
	handler.activate=__Fusion_Charts_ExportHandler_activate;
	handler.getTag=__DoradoElement_getTag;
	handler.setTag=__DoradoElement_setTag;
	handler.$id = id;
	handler.$divId="";
	handler.viewmodel = viewmodel;
	handler.exportComponent=new FusionChartsExportObject(id, __FUSION_CHARTS_PATH + "/FCExporter.swf");
	handler.setDiv=__Fusion_Charts_ExportHandler_SetDiv;
	handler._fireBeforeRenderer=__Fusion_Charts_ExportHandler_FireBeforeRenderer;
	handler.renderer=__Fusion_Charts_ExportHandler_Renderer;
	return handler;
}
DoradoFactory.registerComponentType("ExportHandler", ExportHandler);
function __Fusion_Charts_ExportHandler_SetDiv(divId){
	this.$divId=divId;
}
function __Fusion_Charts_ExportHandler_activate(){}
function __Fusion_Charts_ExportHandler_FireBeforeRenderer(){
	var isContinue = fireDoradoEvent(this, "beforeRenderer", [this.exportComponent]);
	if(!isContinue && typeof(isContinue) != "undefined"){
		return false;
	}
	return true;
}
function __Fusion_Charts_ExportHandler_Renderer(){
	this.exportComponent.componentAttributes.btnsavetitle = '保存';
	this.exportComponent.componentAttributes.btndisabledtitle = '等待..'; 
	if(this._fireBeforeRenderer()){
		this.exportComponent.Render(this.$divId);
	}
}